package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.pojo.ShoppingCart;
import com.sky.result.Result;
import com.sky.service.user.ShoppingCartService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@Api(tags = "C端-购物车")
@RequestMapping("/user/shoppingCart")
public class ShoppingCartController {
    @Autowired
    private ShoppingCartService shoppingCartService;

    @ApiOperation("添加购物车")
    @PostMapping("/add")
    public Result<String> shoppingCartAdd(@RequestBody ShoppingCartDTO shoppingCartDTO) {
        log.info("购物车数据：{}", shoppingCartDTO);
        shoppingCartService.addShoppingCar(shoppingCartDTO);
        return Result.success();
    }
    @ApiOperation("查看购物车")
    @GetMapping("/list")
    public Result<List<ShoppingCart>> query() {
        List<ShoppingCart> shoppingCartList =shoppingCartService.list();
        return Result.success(shoppingCartList);
    }

    @ApiOperation("清空购物车")
    @DeleteMapping("/clean")
    public Result<String> cleanShoppingCart(){
        shoppingCartService.cleanShoppingCart();
        return Result.success();
    }
    @ApiOperation("清空购物车")
    @PostMapping("/sub")
    public Result<String> updateMealNumber(){
        //shoppingCartService.updateMealNumber();
        return Result.success();
    }
}